<?php

	class Mhome extends CI_Model {
		
		function __construct(){
			parent::__construct();
		}
		
		function login($user_id, $user_pwd){
			$sql = "SELECT * FROM user_ WHERE user_id = ".$this->db->escape($user_id)." AND user_pwd ".$this->db->escape($user_pwd)." LIMIT 1";
			return $query->row();
		}
		
		function insert_user(){
			$user_id = $this->input->post('user_id');
			$user_pwd = $user_pwd = $this->encrypt->encode($this->input->post('user_pwd'));
			$user_sex = $this->input->post('user_sex');
			
			$sql = "INSERT INTO user_ (user_id, user_pwd, user_sex, active_key, createdate, modifydate) VALUES(".$this->db->escape($user_id).", ".$this->db->escape($user_pwd).",'$user_sex', UUID(), now(), now())";
			$this->db->query($sql);
			return $this->db->affected_rows();
		}
		
		function update_user($row){
			$this->db->query("UPDATE user_ SET almm_id = ".$this->db->escape($row->almm_id).", user_id = ".$this->db->escape($row->user_id).", user_pwd = ".$this->db->escape($row->user_pwd).", user_sex = ".$this->db->escape($row->user_sex).", active_key = ".$this->db->escape($row->active_key).", modifydate = now() WHERE user_id = ".$this->db->escape($row->user_id)."");
			return $this->db->affected_rows();
		}
		
		function get_user($user_id){
			$sql = "SELECT * FROM user_ WHERE user_id = ".$this->db->escape($user_id)." LIMIT 1";
			$query = $this->db->query($sql);
			return $query->row();
		}
		
		function get_user_1($guid){
			$sql = "SELECT * FROM user_ WHERE active_key = ".$this->db->escape($guid)." LIMIT 1";
			$query = $this->db->query($sql);
			return $query->row();
		}
		
		function active_user($guid){
			if($guid != 'Y'){
				$this->db->query("UPDATE user_ SET active_key = 'Y', modifydate = now() WHERE active_key = ".$this->db->escape($guid)."");
				return $this->db->affected_rows() > 0;
			}
			return false;
		}
		/*
		function get_category()
		{
			$query = $this->db->query('SELECT * FROM category');
			return $query->result();
		}
		function get_article($category_id)
		{
			$query = $this->db->query("SELECT * FROM article WHERE category_id=$category_id");
			return $query->result();
		}
		function get_category_name($category_id)
		{
			$query = $this->db->query("SELECT * FROM category WHERE category_id = $category_id");
			return $query->result();
		}
		function get_article_content($id)
		{
			$query = $this->db->query("SELECT * FROM article WHERE id = $id");
			return $query->result();
		}
		function insert_comment()
		{
			
				$content = $this->input->post('content');
				$article_id = $this->input->post('article_id');
				$author = $this->input->post('author');
				$this->db->query("INSERT INTO comments(id,article_id,content,author,last_date)VALUES('','$article_id','$content','$author',now())");
				return $this->db->affected_rows();
		}
		function get_comment($article_id)
		{
			$query = $this->db->query("SELECT * FROM comments WHERE article_id=$article_id");
			return $query->result();
		}*/
	}